import axios from '../../axios/index'

export interface roleOperation {
    description?: number
    id?: string
    name?: string
    permissionIds?: string[]
}

//创建角色
export const roleCreate = (data: any) => {
    return axios({
        method: 'post',
        url: '/api/user/manage/roles',
        data
    })
}

//修改角色
export const roleUpdate = (data: any) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/roles',
        data
    })
}

//删除角色
export const roleDelete = (id: string) => {
    return axios({
        method: 'delete',
        url: '/api/user/manage/roles',
        params: {
            id
        }
    })
}

export interface rolePageInterface {
    current?: number
    name?: string
    size?: number
}
//角色分页
export const rolePage = (params: rolePageInterface) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/page',
        params
    })
}

//角色列表集合
export const roleList = () => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/list'
    })
}

//分配角色数据权限
export const allocationRoleDataPersmission = (roleId: string, dimensionIds: string[]) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/roles/assign-dimensions',
        data: {
            roleId,
            dimensionIds
        }
    })
}

//获取数据权限 - 树结构
export const dataPersmissionTree = (roleId?: string) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/dimension-trees',
        params: {
            roleId
        }
    })
}

//获取数据权限 - 列表集合
export const dataPersmission = (roleId?: string) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/dimensions',
        params: {
            roleId
        }
    })
}

//获取菜单权限 - 树结构
/**
 *
 * @param types 0菜单，1按钮 ，2接口
 * @returns
 */
export const menuPersmissionTree = (params?: { roleId?: string; diable?: number; types?: string }) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/permission-trees',
        params
    })
}
//获取菜单权限 - 列表集合
export const menuPersmission = (roleId?: string) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/roles/permissions',
        params: {
            roleId
        }
    })
}
